package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author stone
 * @date 2022/08/27 09:11
 */
public class LifeCycleBean implements BeanNameAware, BeanFactoryAware,
        ApplicationContextAware, InitializingBean {

    String parameter1;

    public void setParameter1(String parameter1) {
        System.out.println("设置属性值：set方法");
        this.parameter1 = parameter1;
    }

    public LifeCycleBean() {
        System.out.println("生命周期的开始：Bean的实例化");
    }

    String beanName;
    BeanFactory beanFactory;
    ApplicationContext applicationContext;

    @Override
    public void setBeanName(String beanName) {
        System.out.println("setBeanName");
        this.beanName = beanName;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("setBeanFactory");
        this.beanFactory = beanFactory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("setApplicationContext");
        this.applicationContext = applicationContext;
    }

    public void init() {
        System.out.println("自定义的init方法");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("通过接口实现的init方法");
    }
}
